home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / debugnub / CirioNubProcs0.c < prev    next >
C/C++ Source or Header  |  1992-04-16  |  5KB  |  217 lines

  1. /* begincopyright
  2.   Copyright (c) 1988-1991 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.   endcopyright */
  15.  
  16. /*
  17.  * CirioNubProcs0.c
  18.  *
  19.  * Demers, June 15, 1991 4:57:14 pm PDT
  20.  */
  21.  
  22. #include "xr/Errno.h"
  23. #include "xr/ThreadsBackdoor.h"
  24. #include "xr/CirioNubProtocol.h"
  25. #include "xr/CirioNubMarshall.h"
  26. #include "xr/CirioNubProcs.h"
  27. #include "xr/CirioNubEnvironment.h"
  28.  
  29. #include "xr/ThreadsMsg.h"
  30.  
  31.  
  32. extern CirioNubRetCode
  33. CirioNubStoreBytesToVPTextSegments(/*
  34.     char *bytes,
  35.     char *addr,
  36.     int nBytes
  37. */);
  38.  
  39. extern int
  40. CirioNubFetchBytesFromVPTextSegment(/*
  41.     char *bytes,
  42.     char *addr,
  43.     int nBytes,
  44.     int vpi
  45. */);
  46.  
  47. extern bool
  48. CirioNubIsTextAddress(/*
  49.     char *addr
  50. */);
  51.  
  52. CirioNubRetCode
  53. CirioNubServeNull(argc, args)
  54.     int argc;
  55.     unsigned *args;
  56. {
  57.     unsigned versionRequest, versionReply;
  58.  
  59.     if( argc > 1 ) return(cnrc_badArgs);
  60.  
  61.     versionRequest = args[0];
  62.     if( versionRequest < CIRIO_NUB_PROCS_LOW_VERSION )
  63.         versionReply = CIRIO_NUB_PROCS_LOW_VERSION;
  64.     else if( versionRequest > CIRIO_NUB_PROCS_VERSION )
  65.         versionReply = CIRIO_NUB_PROCS_VERSION;
  66.     else
  67.         versionReply = versionRequest;
  68.  
  69.     return CirioNubPutCard32(
  70.     CIRIO_NUB_VERSION(
  71.         CIRIO_NUB_PROTOCOL_VERSION,
  72.         versionReply
  73.     )
  74.     );
  75. }
  76.  
  77.  
  78. static CirioNubRetCode
  79. CirioNubDoGet(sendProc, addr, len)
  80.     CirioNubRetCode (*sendProc)();
  81.     char *addr;
  82.     int len;
  83. {
  84.     static /* CirioNub is single-threaded! */ long myBuf[2048];
  85.  
  86.     if( CirioNubIsTextAddress(addr) ) {
  87.         if( len > sizeof(myBuf) ) len = sizeof(myBuf);
  88.         if( CirioNubFetchBytesFromVPTextSegment(myBuf, addr, len, 0) >= 0 ) {
  89.             return (*sendProc)(myBuf, len);
  90.         } else {
  91.             return (*sendProc)(NIL, 0);
  92.         }
  93.     } else if( CirioNubCanAccess(addr, len, FALSE) ) {
  94.         return (*sendProc)(addr, len);
  95.     } else {
  96.         return (*sendProc)(NIL, 0);
  97.     }
  98. }
  99.  
  100. CirioNubRetCode
  101. CirioNubServeGetBytes (argc, args)
  102.     int argc;
  103.     unsigned *args;
  104. {
  105.     char *addr;
  106.     int nBytes;
  107.  
  108.     if( argc != 2 ) return(cnrc_badArgs);
  109.     addr = (char *)(args[0]);
  110.     nBytes = (unsigned)(args[1]);
  111.  
  112.     return CirioNubDoGet(CirioNubPutBlock8, addr, nBytes);
  113. }
  114.     
  115.  
  116. static CirioNubRetCode
  117. CirioNubDoPut( data, addr, len )
  118.     char *data;
  119.     char *addr;
  120.     int len;
  121. {
  122.     if( CirioNubIsTextAddress(addr) ) {
  123.         return CirioNubStoreBytesToVPTextSegments(data, addr, len);
  124.     } else if( CirioNubCanAccess(addr, len, TRUE) ) {
  125.         while( len > 0 ) { *addr++ = *data++; len -= (sizeof *addr); }
  126.         return CirioNubPutInt32(0);
  127.     } else {
  128.         return CirioNubPutInt32(-1);
  129.     }
  130. }
  131.  
  132. CirioNubRetCode
  133. CirioNubServePutBytes (argc, args)
  134.     int argc;
  135.     unsigned *args;
  136. {
  137.     char *addr;
  138.     int nBytes;
  139.     char *bytes;
  140.  
  141.     if( argc != 3 ) return(cnrc_badArgs);
  142.     addr = (char *)(args[0]);
  143.     nBytes = (unsigned)(args[1]);
  144.     bytes = (char *)(args[2]);
  145.  
  146.     return CirioNubDoPut(((char *)(bytes)), ((char *)(addr)), nBytes );
  147. }
  148.  
  149.  
  150. CirioNubRetCode
  151. CirioNubServeGetWords16 (argc, args)
  152.     int argc;
  153.     unsigned *args;
  154. {
  155.     short *addr;
  156.     int nBytes;
  157.  
  158.     if( argc != 2 ) return(cnrc_badArgs);
  159.     addr = (short *)(args[0] & (~01));
  160.     nBytes = (unsigned)(args[1]);
  161.  
  162.     return CirioNubDoGet(CirioNubPutBlock16, addr, nBytes);
  163. }
  164.     
  165.  
  166. CirioNubRetCode
  167. CirioNubServePutWords16 (argc, args)
  168.     int argc;
  169.     unsigned *args;
  170. {
  171.     short *addr;
  172.     int nBytes;
  173.     short *bytes;
  174.  
  175.     if( argc != 3 ) return(cnrc_badArgs);
  176.     addr = (short *)(args[0] & (~0x1));
  177.     nBytes = (unsigned)(args[1]);
  178.     bytes = (short *)(args[2] & (~0x1));
  179.  
  180.     return CirioNubDoPut(((char *)(bytes)), ((char *)(addr)), nBytes );
  181. }
  182.  
  183.  
  184. CirioNubRetCode
  185. CirioNubServeGetWords32 (argc, args)
  186.     int argc;
  187.     unsigned *args;
  188. {
  189.     long *addr;
  190.     int nBytes;
  191.  
  192.     if( argc != 2 ) return(cnrc_badArgs);
  193.     addr = (long *)(args[0] & (~0x3));
  194.     nBytes = (unsigned)(args[1]);
  195.  
  196.     return CirioNubDoGet(CirioNubPutBlock32, addr, nBytes);
  197. }
  198.  
  199.  
  200. CirioNubRetCode
  201. CirioNubServePutWords32 (argc, args)
  202.     int argc;
  203.     unsigned *args;
  204. {
  205.     long *addr;
  206.     int nBytes;
  207.     long *bytes;
  208.  
  209.     if( argc != 3 ) return(cnrc_badArgs);
  210.     addr = (long *)(args[0] & (~0x3));
  211.     nBytes = (unsigned)(args[1]);
  212.     bytes = (long *)(args[2] & (~0x3));
  213.  
  214.     return CirioNubDoPut(((char *)(bytes)), ((char *)(addr)), nBytes );
  215. }
  216.  
  217.